$(function () {
    obj.init();
});

var obj = new function() {
    return {
        addAreaProvForm: null,
        form: null,
        init: function () {
            this.addAreaProvForm = $('#addAreaProv_form');
            this.form = new xhForm(this.addAreaProvForm);
            this.funObj().addDataToProvAction();
            this.listener();
        },
        listener: function () {
            var $this = this;
            this.addAreaProvForm.find('input[name=province]').bind('click', function(){
                if(this.checked){//选中时单选
                    $('#addAreaProv_form').find("input[name=province]").not(this).attr("checked", false);
                }
            });
            $('#bt_modal_confirm',parent.document).click(function () {
                $this.funObj().saveData();
            });
        },
        funObj: function () {
            return {
                addDataToProvAction: function () {
                    str = '';
                    $.each(provIds, function (value, name) {
                        if (existIds && $.inArray(value, existIds) !== -1){
                            str += '<label style="width: fit-content">' +
                                '<input type="checkbox" name="exist" checked="checked" disabled value="' + value + '">'+ '<span style="color: darkgray;padding-right: 60px" >'+ name +'</span>' +
                                '</label>';
                        } else {
                            str += '<label style="width: fit-content">' +
                                '<input type="checkbox" name="province" value="' + value + '">'+ '<span style="padding-right: 60px">'+ name +'</span>' +
                                '</label>';
                        }
                    });
                    $('#prov_list').append($(str));
                },
                saveData: function () {
                    var province = $('input[name=province]:checked').val();
                    xhExtra.setBtnNormal($('#bt_modal_confirm',parent.document));
                    window.top.xhTop.closeModal();
                    window.top.xhTop.getActiveFrame().obj.funObj().addProvData(province);
                }
            }
        }
    }
};
